home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
prodpack.zip
/
DB4PPSRC.EXE
/
_OPENDBF.PRG
< prev
next >
Wrap
Text File
|
1993-05-04
|
7KB
|
224 lines
*' $Header: E:/test/sysproc/doc/_opendbf.prv 1.0 12 Aug 1992 16:55:52 Bill Ramos $
*----------------------------------------------------------------------
* PROCEDURE AND FUNCTIONS
* PROCEDURE _OpenDbf
* PROCEDURE _OpenIt
*----------------------------------------------------------------------
PROCEDURE _OpenDbf
PARAMETERS pc_file, pn_wa, pl_ok, pl_nolog, p__alias, pl_keepwa, pl_exclus
*---------------------------------------------------------------------
* NAME
* _OpenDbf - opens a DBF using PATH or Catalog
*
* DESCRIPTION
* The _OpenDbf procedure will open the DBF file in the <pn_wa>
* work area. If it opened the DBF file OK, then <pl_ok> is
* set to .T., otherwise it is set to .F. _OpenDbf will leave
* the opened file as the current work area.
*
* If the file is already opened in another work area, _OpenDbf
* will close it, and re-open the file in the desired work area.
*
* If there is an error, _OpenDbf will display the [File not found]
* error message.
*
* SYNOPSIS
* DO _OpenDbf WITH <pc_file>, <pn_wa>, <pl_ok>, <pl_nolog>, <pl_keepwa>
*
* PARAMETERS
* pc_file = name of DBF file to open
* pn_wa = work area to use for the file
* pl_ok = if opened, set to .t., else set to .f.
* pl_nolog = .T. use with NOLOG, .F. normal USE for transactions
* p__alias = Alias name for the dbf, OPENS WITH "AGAIN NOUPDATE"
* pl_keepwa = .T. keep open in its current WA, .F. close and reopen
* in the assigned WA
* pl_exclus = If file should be opened exclusively
*
* EXAMPLE
* *-- Re-use the file in the desired work area
* USE GOODS IN 15
* ok = .T.
* DO _OpenDbf WITH "GOODS", 1, ok && Opens GOODS in work area 1 vs 15
*
* *-- Use the file in an available work area
* ok = .T.
* DO _OpenDbf WITH "VENDORS", SELECT(), ok
* IF .NOT. ok && If the file was not opened
* ... && Error recovery code here
* ENDIF
*
* LIMITATIONS
* None
*
* DEPENDENCIES
* Calls: _CatOpen, _CatClose, _CatCode, _Err_Box
*
*---------------------------------------------------------------------
PRIVATE lc_dbfname, lc_file, ll_catclsd, ll_opened, ln_code, ln_select
PRIVATE lCatalog
lCatalog = SET( "CATALOG" ) = "ON" .AND. .NOT. ISBLANK( CATALOG() )
SET CATALOG OFF
pl_ok = .F. && Assume open will fail
lc_file = TRIM( UPPER( pc_file ) ) && Trim the file name
lc_dbfname = lc_file + ".DBF" && Form the DBF name for checks
ll_catclsd = .T. && Catalog closed to start flag
IF FILE( lc_dbfname ) && If the file exists
ln_select = SELECT( pc_file ) && See if the file is already opened
IF ln_select > 0 .AND. ;
ln_select <> pn_wa && If file is open in wrong WA
IF .NOT. pl_keepwa
IF TYPE( "p__alias" ) = "L" && If no alias is defined, then
USE IN ( ln_select ) && Close the file first
ENDIF
ELSE
SELECT ( ln_select )
ENDIF
ENDIF
DO _OpenIt && Open the given file
ELSE && ... the file is not in path
IF SELECT( "FXCATALOG" ) = 0 && If catalog is not open already
ll_opened = .F. && Assume that can't open catalog
DO _CatOpen WITH ll_opened && try an open the catalog
ELSE
ll_opened = .T. && Flag catalog is open
ll_catclsd = .F. && Flag don't close catalog on exit
ENDIF
IF ll_opened
SELECT FXCatalog && Position to opened catalog
ln_code = 0
DO _CatCode WITH lc_dbfname, ;
ln_code && Try and locate the DBF file
IF FOUND() && If the file is in the catalog
lc_dbfname = FxCatalog->path && Grab the full file path
IF FILE( lc_dbfname ) && If the file is still around
ln_select = SELECT( lc_file ) && See if the file is already opened
IF ln_select > 0 .AND. ;
ln_select <> pn_wa && If file is open in wrong WA
IF .NOT. pl_keepwa
USE IN ( ln_select ) && Close the file first
ELSE
SELECT ( ln_select )
ENDIF
ENDIF
DO _OpenIt && Open the given file
ENDIF
ELSE
DO _Err_Box WITH [Cannot open file: ] + lc_dbfname
ll_opened = .F.
ENDIF
IF ll_catclsd && If the catalog was closed before
DO _CatClose && Close the catalog file
ENDIF
ENDIF && ll_opened
ENDIF && FILE( lc_dbfname )
IF lCatalog
SET CATALOG ON
ENDIF
RETURN
*-- EOP: _OpenDbf WITH pc_file, pn_wa, pl_ok, pl_nolog, p__alias, ;
*-- pl_keepwa, pl_exclus
PROCEDURE _OpenIt
*---------------------------------------------------------------------
* NAME
* _OpenIt
*
* DEPENDENCIES
* Must be called by _OpenDbf
*
* VARIABLES
* ll_exclus = Save current EXCLUSIVE setting
* All other variables for the routine come from _OpenDbf
*
*---------------------------------------------------------------------
PRIVATE ll_exclus && Save EXCLUSIVE setting
IF .NOT. pl_keepwa
SELECT ( pn_wa ) && Select the desired work area
IF pl_exclus .AND. SET( "EXCLUSIVE" ) = "OFF"
*-- If file should be opened exclusively and exclusive isn't already ON.
ll_exclus = .T.
SET EXCLUSIVE ON
ELSE
ll_exclus = .F.
ENDIF
IF pl_nolog
IF TYPE("p__alias ") = "L"
USE ( lc_dbfname ) ;
ALIAS &lc_file NOLOG && Open the file with NOLOG option
ELSE
*-- Open the file with ALIAS option
USE ( lc_dbfname ) ;
ALIAS &p__alias NOLOG AGAIN NOUPDATE ;
ENDIF
ELSE
IF TYPE("p__alias ") = "L"
USE ( lc_dbfname ) ALIAS &lc_file
ELSE
*-- Open the file with ALIAS option
USE ( lc_dbfname ) ALIAS &p__alias AGAIN NOUPDATE
ENDIF
ENDIF
IF ll_exclus
SET EXCLUSIVE OFF
ENDIF
ENDIF
IF TYPE( "FXL_Error" ) <> "L"
IF _FileRoot( lc_dbfname ) = _FileRoot( DBF() )
pl_ok = .T.
ELSE
pl_ok = .F.
DO _Err_Box WITH [Cannot open file: ] + lc_dbfname
ENDIF
ELSE
pl_ok = .F.
RELEASE FXL_Error
ENDIF
RETURN
*-- EOP: _OpenIt
*'-------------------------------------------------------------------------
*' $Log: E:/test/sysproc/doc/_opendbf.prv $
*'-------------------------------------------------------------------------